package com.fivemin.website_statistics.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fivemin.website_statistics.enums.ResponseEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class R {
    private int code;
    private String msg;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object data;

    public R OK(Object data){
        return new R(ResponseEnum.OK.getCode(),ResponseEnum.OK.getMsg(),data);
    }
    public R error(Object data){
        return new R(ResponseEnum.ERROR.getCode(),ResponseEnum.ERROR.getMsg(),data);
    }

    public R error(ResponseEnum responseEnum,Object data){
        return new R(responseEnum.getCode(),responseEnum.getMsg(),data);
    }

    public R error(ResponseEnum responseEnum,String msg,Object data){
        return new R(responseEnum.getCode(),msg,data);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
